<extend name="Public/base"/>

<block name="body">
    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
    <div class="main-title">
        <h2>{$meta_title}</h2>
    </div>
    <form action="{:U('Common/addCommon')}" method="post" class="form-horizontal">
        <div class="form-item">
            <label class="item-label">商品名</label>
            <div class="controls">
                <input type="text" class="text input-large" name="name" value="{$data.name|default=''}">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">商品名<span class="check-tips">（英文名）</span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="e_name" value="{$data.e_name|default=''}">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">商品分类</label>
            <div class="controls">
            <select name="class_id">
                <option value="0" selected="">--请选择--</option>
                <volist name="_class" id="v">
                    <option value="{$v.id}" <if condition="$v['id'] eq $data['class_id']">selected="selected"</if>>{$v.name}</option>          
                    <volist name="v['_child']" id="v2">
                        <option value="{$v2.id}" <if condition="$v2['id'] eq $data['class_id']">selected="selected"</if>>&nbsp;&nbsp;├{$v2.name}</option>
                    </volist>
                </volist>
            </select>               
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">商品品牌</label>
            <div class="controls">
            <select name="brand_id">
                <volist name="_brand" id="v">
                    <option value="{$v.id}" <if condition="$v['id'] eq $data['brand_id']">selected="selected"</if>>{$v.name}</option>          
                </volist>
            </select>               
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">价格</label>
            <div class="controls">
                <input type="text" class="text input-large" name="price" value="{$data.price|default='0.00'}">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">喜欢数</label>
            <div class="controls">
                <input type="text" class="text input-large" name="like" value="{$data.like|default=0}">
            </div>
        </div>
        <div class="controls">
            <label class="item-label">图片</label>
            <input type="file" id="upload_picture">
            <input type="hidden" name="picture" id="picture" value="{$data.picture|default=''}"/>
            <div class="upload-img-box">
            <notempty name="data['picture']">
                <div class="upload-pre-item"><img src="{$data.picture|get_cover='path'}"/></div>
            </notempty>
            </div>
        </div>
        <script type="text/javascript">
        //上传图片
        /* 初始化上传插件 */
        $("#upload_picture").uploadify({
            "height"          : 30,
            "swf"             : "__STATIC__/uploadify/uploadify.swf",
            "fileObjName"     : "download",
            "buttonText"      : "上传图片",
            "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
            "width"           : 120,
            'removeTimeout'   : 1,
            'fileTypeExts'    : '*.jpg; *.png; *.gif;',
            "onUploadSuccess" : uploadPicture,
            'onFallback' : function() {
                alert('未检测到兼容版本的Flash.');
            }
        });
        function uploadPicture(file, data){
            var data = $.parseJSON(data);
            var src = '';
            if(data.status){
                $("#picture").val(data.id);
                src = data.url || '__ROOT__' + data.path;
                $("#picture").parent().find('.upload-img-box').html(
                    '<div class="upload-pre-item"><img src="' + src + '"/></div>'
                );
            } else {
                updateAlert(data.info);
                setTimeout(function(){
                    $('#top-alert').find('button').click();
                    $(that).removeClass('disabled').prop('disabled',false);
                },1500);
            }
        }
        </script>
        <div class="form-item">
            <label class="item-label">是否上架/下架</label>
            <div class="controls">
                <label class="radio">
                    <input type="radio" value="0" name="is_sj" <if condition="$data['is_sj'] eq 0">checked="checked"</if>>下架                                    
                </label>
                <label class="radio">
                    <input type="radio" value="1" name="is_sj" <if condition="$data['is_sj'] eq 1">checked="checked"</if>>上架
                </label>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">是否推荐</label>
            <div class="controls">
                <label class="radio">
                    <input type="radio" value="0" name="is_recommend" <if condition="$data['is_recommend'] eq 0">checked="checked"</if>>否                                    
                </label>
                <label class="radio">
                    <input type="radio" value="1" name="is_recommend" <if condition="$data['is_recommend'] eq 1">checked="checked"</if>>是
                </label>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">是否热销</label>
            <div class="controls">
                <label class="radio">
                    <input type="radio" value="0" name="is_hot" <if condition="$data['is_hot'] eq 0">checked="checked"</if>>否                              
                </label>
                <label class="radio">
                    <input type="radio" value="1" name="is_hot" <if condition="$data['is_hot'] eq 1">checked="checked"</if>>是
                </label>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">内容</label>
            <div class="controls">
                <label class="textarea">
                    <textarea name="content">{$data.content}</textarea>
                    {:hook('adminArticleEdit', array('name'=>'content','value'=>$data['content']))}
                </label>
            </div>
        </div>
        <div class="form-item">
            <input type="hidden" name="table" value="goods">
            <input type="hidden" name="methods" value="Goods">
            <input type="hidden" name="fields" value="class_id,text;brand_id,text;name,text;e_name,text;price,text;picture,text;like,text;is_sj,text;is_recommend,text;is_hot,text;content,text;ctime,date;">
            <input type="hidden" name="id" value="{$data.id|default=0}">
            <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</block>

<block name="script">
    <script type="text/javascript">
        //导航高亮
        highlight_subnav('{:U('Goods/index')}');
    </script>
</block>
